Uec3.PartnerPWindow = Ext.extend(Ext.util.Observable, {
	
	constructor : function(config) {
    this.addEvents({show:true});
    this.module = config.module;
    this.desktop = this.module.app.getDesktop();
    this.win = this.desktop.getWindow('partner');
    if (!this.win) {
    this.win = this.desktop.createWindow({
		id : 'partner',
		title : '往来单位',
		width : document.body.clientWidth * 1.0,
		height : document.body.clientHeight * 1.0,
		iconCls : 'acc-icon',
		shim : false,
		closable : true,
		animCollapse : false,
		constrainHeader : true,
		maximizable : true,
		maximized : true,
		taskbuttonTooltip : "往来单位",
		layout : "border",
		resizable : true,
		tools : [{id : 'refresh',handler : Ext.emptyFn,scope : this}],
		items : [this.init(config)]
	});
}},
//浏览往来单位
browsePartner : function(grid, rowIndex, colIndex, item, e) {
	this.partnerAddress_ds.removeAll();
	var record = this.partner_ds.getAt(rowIndex);
	var partnerId = record.get('id');
	this.partner_form.getForm().loadRecord(record);
	this.partner_win.buttons[0].hide();
	this.partner_win.buttons[1].hide();
	this.partner_win.buttons[2].hide();
	this.partner_win.buttons[3].hide();
	this.partner_win.buttons[4].hide();
	this.partner_win.buttons[5].hide();	
	// partner_win.show.defer(2000,partner_win);
	this.partner_win.show();
	this.partnerAddress_ds.baseParams = {partnerId : partnerId};
	this.partnerAddress_ds.load();
	this.partner_win.setTitle('浏览客户-按Esc退出');
	this.maskTopField.show();
},
//编辑往来单位
editPartner : function(grid, rowIndex, colIndex, item, e){
	this.partnerAddress_ds.removeAll();
	var record = this.partner_ds.getAt(rowIndex);
	var partnerId = record.get('id');
	this.partner_form.getForm().loadRecord(record);
	var companyId = record.get("companyId");
	if (companyId) {
		this.partner_win.buttons[0].show();
		this.partner_win.buttons[1].hide();
		this.partner_win.buttons[2].hide();
		this.partner_win.buttons[3].hide();
		this.partner_win.buttons[4].hide();
		this.partner_win.buttons[5].show();
		this.partner_form.getForm().findField("code").setReadOnly(true);
		this.partner_form.getForm().findField("taxCode").setReadOnly(true);
		this.partner_form.getForm().findField("business").setReadOnly(true);
		this.partner_form.getForm().findField("contactorIdentityCode").setReadOnly(true);
		this.partner_form.getForm().findField("name").setReadOnly(true);
		this.partner_form.getForm().findField("contactor").setReadOnly(true);
	} else {
		this.partner_win.buttons[0].hide();
		this.partner_win.buttons[1].show();
		this.partner_win.buttons[2].hide();
		this.partner_win.buttons[3].hide();
		this.partner_win.buttons[4].show();
	    this.partner_win.buttons[5].show();
		this.partner_win.buttons[6].show();
		this.partner_form.getForm().findField("code").setReadOnly(false);
		this.partner_form.getForm().findField("taxCode").setReadOnly(false);
		this.partner_form.getForm().findField("business").setReadOnly(false);
		this.partner_form.getForm().findField("contactorIdentityCode").setReadOnly(false);
		this.partner_form.getForm().findField("name").setReadOnly(false);
		this.partner_form.getForm().findField("contactor").setReadOnly(false);		
	}
	var province = record.get('province');
	var city = record.get('city');
	var provinceId = record.get('provinceId');
	var cityId = record.get('cityId');
	if (province != "") {
		this.partner_city_cmb.getStore().setBaseParam("prov", provinceId);
		this.partner_city_cmb.getStore().load();
	}
	if (city != "") {
		this.partner_dist_cmb.getStore().setBaseParam("city", cityId);
		this.partner_dist_cmb.getStore().load();
	}
	this.partnerAddress_ds.baseParams = {
		partnerId : partnerId
	};
	this.partnerAddress_ds.load();
	this.partner_win.setTitle('编辑客户-按Esc退出');
	this.partner_win.buttons[5].setText('更新');
	this.partner_win.show();

},
//恢复往来单位
revertPartner : function(grid, rowIndex, colIndex, item, e) {
	var record = this.partner_ds.getAt(rowIndex);
	var name = record.get("name");
	var id= record.get("id");
	var companyId = record.get("companyId");
	this.partner_grid.loadMask.show();
	if (companyId == 0 || companyId == "") {revert(this.partner_ds, this.partner_grid, record, id);} 
	else {checkCertify(this.partner_ds, this.partner_grid, record, id, companyId, name,companyId);}
},
deletePartner : function(grid, rowIndex, colIndex, item, e) {
	var record = this.partner_ds.getAt(rowIndex);
	Ext.Msg.confirm('信息', '确定要删除?', function(btn) {
				if (btn == 'yes') {
					this.partner_grid.loadMask.show();
					var partnerId = record.get('id');
					Ext.Ajax.request({
								url : Uec3.App.Constants.homeUrl+ '/partner/query_partner!delete.do',
								success : function(res) {
									var result = res.responseText;
									if (!result) {this.partner_grid.loadMask.hide();this.partner_ds.remove(record);this.partner_ds.reload();Ext.Msg.alert("提示", "删除成功");
									} else {this.partner_grid.loadMask.hide();Ext.Msg.alert("提示",Ext.decode(result).failure);}
								},
								failure : function(res) {this.partner_grid.loadMask.hide();Ext.Msg.alert("提示", "网络异常,请重先连接");},
								params : {id : partnerId},scope:this
							});
				}
			},this);
},
// 删除PartnerAddress对象
deletePartnerAddress : function(grid,rowIndex,colIndex,item,e){
	var record = this.partnerAddress_ds.getAt(rowIndex);
	this.partnerAddress_ds.remove(record);
	this.partnerAddress_grid.view.refresh();

},
show:function(){	
    this.win.show();
},
/**
pctChange: function(val) {
	if (val > 0) {
		return '<span style="color:green;">' + val + '%</span>';
	} else if (val < 0) {
		return '<span style="color:red;">' + val + '%</span>';
	}
	return val;
},*/
getGridComboBox:function(){
	// 区县下拉框
	this.partner_dist_cmb = getDistrictCombox(Uec3.App.Constants.homeUrl);
	this.partner_dist_cmb.setWidth(100);
	// 城市下拉框
	this.partner_city_cmb = getCityCombox(Uec3.App.Constants.homeUrl,this.partner_dist_cmb);
	this.partner_city_cmb.setWidth(100);
	// 省份下拉框
	this.partner_prov_cmb = getProvinceCombox(Uec3.App.Constants.homeUrl,this.partner_city_cmb,this.partner_dist_cmb);
	this.partner_prov_cmb.setWidth(100);
	// 区县下拉框
	this.company_dist_cmb = getDistrictCombox(Uec3.App.Constants.homeUrl);
	this.company_dist_cmb.setWidth(100);this.company_dist_cmb.setDisabled(true);this.company_dist_cmb.anchor = "99%";
	// 城市下拉框
	this.company_city_cmb = getCityCombox(Uec3.App.Constants.homeUrl,this.company_dist_cmb);
	this.company_city_cmb.setWidth(100);this.company_city_cmb.setDisabled(true);this.company_city_cmb.anchor = "99%";
	// 省份下拉框
	this.company_prov_cmb = getProvinceCombox(Uec3.App.Constants.homeUrl,this.company_city_cmb, this.company_dist_cmb);
	this.company_prov_cmb.setWidth(100);this.company_prov_cmb.setDisabled(true);this.company_prov_cmb.anchor = '99%';
},

 render_partnerAddressDesc:function(value, cellmeta, record,rowIndex, columnIndex, store) {
	var str = "<a style='font-size:12px' href='javascript:Ext.CUR_APP.getModule(\"partner\").deletePartnerAddress("+ rowIndex + ");'>删除</a>";
	return str;
},
  savePartner:function(partner_win, partner_form, partner_ds,partnerAddress_ds){
			if (!partner_form.getForm().isValid()) {
					Ext.Msg.alert("提示", "请按要求进行正确操作");
					return;
				}
				var formValues = partner_form.getForm().getValues();
				var jsonArray = [];  var partner_json = [];
				Ext.each(partnerAddress_ds.getRange(), function(item) {jsonArray.push(item.data);});
				partner_json.push(formValues);  partner_json.push(jsonArray);
				var jsonAll = Ext.encode(partner_json);
				var text = partner_win.buttons[5].getText();
				if (text == "增加") {
					partner_form.getForm().findField('id').setValue('');
					partner_form.getForm().findField('companyId').setValue('');
					partner_form.getForm().findField('areaId').setValue('');
					partner_form.getForm().findField('ownerId').setValue('');
					partnerAddress_ds.removeAll();
				}
              this.partner_ajax.request({
				url : Uec3.App.Constants.homeUrl+ '/partner/query_partner!save.do',
				success : function(res) {
					var result = Ext.decode(res.responseText);
					if (result.success == "OK") {
						if (result.partner.id) {
							partner_form.getForm().findField("id").setValue(result.partner.id);
							partner_form.getForm().findField("areaId").setValue(result.partner.areaId);
							if (text == "增加") {Ext.Msg.alert('提示', "增加客户资料成功!");}
							partner_win.buttons[5].setText('更新');					
							partnerAddress_ds.baseParams = {partnerId : result.partner.id};
			    			partnerAddress_ds.load();
						}
						    partner_ds.reload();
					} else {Ext.Msg.alert("提示", result.failure);}
			},
				failure : function(res) {Ext.Msg.alert('失败', "网络出现异常,请重先连接");},
				params : {queryParam : jsonAll}
			});
},
getAndRestorePartner:function() {
	this.partnerAddress_storeProvince = new Ext.data.Store({
				proxy : new Ext.data.HttpProxy({url : Uec3.App.Constants.homeUrl+ '/area/toSelect.do'}),
				reader : new Ext.data.JsonReader({root : 'areas'}, [{name : 'id'},{name : 'province'}])});

	this.partnerAddress_storeCity = new Ext.data.Store({
				proxy : new Ext.data.HttpProxy({url : Uec3.App.Constants.homeUrl+ '/area/toSelect.do'}),
				reader : new Ext.data.JsonReader({root : 'areas'}, [{name : 'id'}, {name : 'city'}])
			});

	this.partnerAddress_storeCounty = new Ext.data.Store({
				proxy : new Ext.data.HttpProxy({url : Uec3.App.Constants.homeUrl+ '/area/toSelect.do'}),
				reader : new Ext.data.JsonReader({root : 'areas'}, [{name : 'id'}, {name : 'district'}])
			});

	this.partner_ds = new Ext.data.Store({
				proxy : new Ext.data.HttpProxy({url : Uec3.App.Constants.homeUrl+ '/partner/query_partner!query.do'}),
				baseParams : {start : 0,limit : 20},
				pruneModifiedRecords : true,
				reader : new Ext.data.JsonReader({
				            totalProperty : 'totalProperty',
							root : 'root'}, [
								{name : 'id',type : 'int'},
								{name : 'companyId',type : 'int'}, 
								{name : 'ownerId'},
								{name : 'areaId',type : 'int'}, 
								{name : 'name'}, 
								{name : 'taxCode'}, 
								{name : 'pyCode'}, 
								{name : 'contactor'},
								{name : 'contactorIdentityCode'},
								{name : 'code'}, 
								{name : 'simpleName'},
								{name : 'nameEn'}, 
								{name : 'business'},
								{name : 'province'},
								{name : 'provinceId'},
								{name : 'city'}, 
								{name : 'cityId'},
								{name : 'district'}, 
								{name : 'address'},
								{name : 'postcode'},
								{name : 'tel'}, 
								{name : 'fax'}, 
								{name : 'invoicAddress'},
							    {name : 'bankName'},
							    {name : 'email'}, 
							    {name : 'bankCode'}, 
							    {name : 'qq'}, 
							    {name : 'msn'}, 
							    {name : 'web'}, 
							    {name : 'discount',type : 'float'}, 
							    {name : 'relation'}, 
							    {name : 'unpaid',type : 'float'},
							    {name : 'paid',type : 'float'},
							    {name : 'unreceived',type : 'float'},
							    {name : 'received',type : 'float'},
							    {name : 'gmtCreate',type : 'string'},
							    {name : 'gmtModify',type : 'string'},
							    {name : 'isDelete',type : 'int'}
						]),
				remoteSort : true,sortInfo : {field : "id",direction : "asc"}
			});

	this.partnerAddress_ds = new Ext.data.Store({
		proxy : new Ext.data.HttpProxy({url : Uec3.App.Constants.homeUrl+ '/partnerAddress/query_partnerAddress!query.do'}),
		pruneModifiedRecords : true,
		reader : new Ext.data.JsonReader({root : 'root'}, this.partnerAddress_record),
		sortInfo : {field : "receiverName",direction : "asc"}
	});
},
 getPartnerCommonObject:function(config) {
	// 行记录对象
	this.partnerAddress_record = Ext.data.Record.create([
		    {name : 'id'}, 
		    {name : 'partnerId'},
		    {name : 'areaId'}, 
		    {name : 'province'}, 
		    {name : 'city'},
		    {name : 'provinceId'},
		    {name : 'cityId'}, 
		    {name : 'district'},
		    {name : 'street'},
		    {name : 'postCode'}, 
		    {name : 'receiverName'}, 
		    {name : 'phone'}, 
		    {name : 'mobile'}]);
},
componentInitsPartner :function() {
	// /得到下拉菜单列表
	this.getGridComboBox();
	this.partner_ajax=new Ext.data.Connection();
	// 初始化combox对象
	this.partnerAddress_comboProvince = new Ext.form.ComboBox({
				name : 'province',
				store : this.partnerAddress_storeProvince,
				fieldLabel : '省份',
				emptyText : '--请选择--',
				mode : 'local',
				triggerAction : 'all',
				valueField : 'province',
				displayField : 'province',
				forceSelection : true,
				selectOnFocus : true,
				typeAhead : true,
				loadingText : '加载中...',
				editable : false
			});

	this.partnerAddress_storeProvince.load();
	this.partnerAddress_comboCity = new Ext.form.ComboBox({
				name : 'city',store : this.partnerAddress_storeCity,
				fieldLabel : '城市',emptyText : '--请选择--',
				mode : 'local',triggerAction : 'all',
				forceSelection : true,valueField : 'city',
				displayField : 'city',loadingText : '加载中...',
				editable : false
			});

	this.partnerAddress_comboCounty = new Ext.form.ComboBox({
				name : 'district',fieldLabel : '地区',
				store : this.partnerAddress_storeCounty,emptyText : '--请选择--',
				mode : 'local',triggerAction : 'all',
				forceSelection : true,valueField : 'district',
				displayField : 'district',loadingText : '加载中...',editable : false
			})

	this.partner_comboRelation = Uec3.App.dictionary.getCombo('partner_relation',{
				hiddenName : 'relation',fieldLabel : '往来关系(*)',forceSelection : true,emptyText : '--请选择--',
				width : 100,anchor : '99%',allowBlank : false,blankText : "往来关系不能为空"
			});
		
	var companyType_combox = Uec3.App.dictionary.getCombo('company_rtype',{
				hiddenName : 'companyType',allowBlank : false,fieldLabel : '公司类型',blankText : '公司类型不能为空',
				emptyText : '--请选择--',anchor : '99%',disabled : true,forceSelection : true
			});
	var query_partner_form = new Ext.form.FormPanel({
				buttonAlign : 'center',
				frame : false,
				layout : 'form',
				border : false,
				labelWidth : 42,
				items : [
					{xtype : 'textfield',name : 'relation',width : 125,hidden : true},
					{xtype : 'textfield',name : 'isDelete',width : 125,value:'0',hidden : true},
					{xtype : 'textfield',fieldLabel : '名称',name : 'name',width : 125},
					{xtype : 'textfield',fieldLabel : '拼音',name : 'pyCode',width : 125},
					{xtype : 'textfield',fieldLabel : '负责人',name : 'contactor',width : 125}],
				buttons : [{
					style : 'margin-left:42px',text : '查找',scope:this,
					handler : function() {
						var formValues = query_partner_form.getForm().getValues();
						var jsonAll = Ext.encode(formValues);
						this.partner_ds.baseParams = {start : 0,limit : 20,jsonAll : jsonAll}
						this.partner_ds.reload();
					}
				}]
			})
	// 已认证公司注册信息
	var formReader = new Ext.data.JsonReader(

	{
				root : 'root'
			}, [{name : 'id',type : 'int'}, 
				{name : 'email',type : 'string'},
				{name : 'name',type : 'string'}, 
				{name : 'contactorIdentityCode',type : 'string'},
				{name : 'fax',type : 'string'},
				{name : 'invoicAddress',type : 'string'},
				{name : 'bankName',type : 'string'},
				{name : 'bankCode',type : 'string'},
				{name : 'address',type : 'string'},
				{name : 'qq',type : 'string'},
				{name : 'msn',type : 'string'}, 
				{name : 'web',type : 'string'}, 
				{name : 'contactor',type : 'string'},
				{name : 'companyType',type : 'int'}, 
				{name : 'taxCode',type : 'string'}, 
				{name : 'areaId',type : 'int'},
				{name : 'code',type : 'string'},
				{name : 'simpleName',type : 'string'}, 
				{name : 'nameEn',type : 'string'}, 
				{name : 'business',type : 'string'}, 
				{name : 'postcode',type : 'string'}, 
				{name : 'tel',type : 'string'}]
	);
	this.companyForm = new Ext.form.FormPanel({
		labelAlign : 'right',
		title : '已认证往来单位注册信息',
		closable : false,
		frame : true,
		height : 360,
		labelWidth : 80,
		loadingText : '加载数据中...',
		buttonAlign : 'center',
		url : '',
		reader : formReader,
		items : [{
			xtype : 'fieldset',
			title : '基本信息',
			height : 125,
			collapsed : false,
			items : [{
				layout : 'column',
				items : [{
					columnWidth : 0.5,
					items : [{
								layout : 'form',
								labelWidth : 70,
								items : [{name : 'id',fieldLabel : 'ID',xtype : 'hidden'}, 
									     {name : 'areaId',fieldLabel : 'areaId',xtype : 'hidden'}, 
									     {xtype : 'textfield',fieldLabel : '公司名称',name : 'name',width : 150,readOnly : true,
									     style : {background : '#dddddd'},anchor : '99%',allowBlank : false,blankText : "公司名称不允许为空",maxLengthText : "公司名称长度不大于30位"
										}]
							}, {
								layout : 'form',labelWidth : 70,
								items : [{xtype : 'textfield',fieldLabel : '公司简称',name : 'simpleName',readOnly : true,
											style : {background : '#dddddd'},anchor : '99%',maxLength : 30,maxLengthText : "公司简称长度不大于20位"
										}]
							}, {
								layout : 'column',
								items : [{
									columnWidth : 0.5,
									items : [{
										layout : 'form',labelWidth : 70,
										items : [{
											xtype : 'textfield',fieldLabel : '负责人/法人',name : 'contactor',readOnly : true,
											style : {background : '#dddddd'},anchor : '99%',allowBlank : false,blankText : "公司法人名称必须填写",
											maxLength : 30,maxLengthText : "负责人/法人长度不大于20位"
										}]
									}]
								}, {
									columnWidth : 0.5,
									items : [{layout : 'form',labelAlign : 'right',labelWidth : 70,items : [companyType_combox]}]
								}]
							}]
				}, {
					columnWidth : 0.5,
					items : [{
								layout : 'form',labelWidth : 70,labelAlign : 'right',
								items : [{
											xtype : 'textfield',fieldLabel : '经营项目',
											name : 'business',readOnly : true,style : {background : '#dddddd'},
											anchor : '99%',maxLength : 30,maxLengthText : "经营项目长度不大于30位"
										}]
							}, {
								layout : 'form',labelWidth : 70,
								items : [{
											xtype : 'textfield',fieldLabel : '英文名称',readOnly : true,
											style : {background : '#dddddd'},anchor : '99%',name : 'nameEn',
											maxLength : 30,maxLengthText : "英文名称长度不大于30位"
										}]
							}, {
								layout : 'column',labelWidth : 70,
								items : [{
									columnWidth : 0.4,
									items : [{layout : 'form',labelWidth : 70,items : [this.company_prov_cmb]}]
								}, {
									columnWidth : 0.3,
									items : [{layout : 'form',labelWidth : 30,items : [this.company_city_cmb]}]
								}, {
									columnWidth : 0.3,
									items : [{layout : 'form',labelWidth : 30,items : [this.company_dist_cmb]}]
								}]
							}]
				}]
			}]
		}, {
			xtype : 'fieldset',title : '联系方式',height : 145,
			items : [{
				layout : 'column',
				items : [{
					columnWidth : 0.5,
					items : [{
								layout : 'form',labelWidth : 70,labelAlign : 'right',
								items : [{
											xtype : 'textfield',fieldLabel : '通讯地址',
											name : 'address',readOnly : true,
											style : {background : '#dddddd'},
											anchor : '99%',maxLength : 30,
											maxLengthText : "通讯地址长度不大于30位"
										}]
							}]
				}, {
					columnWidth : 0.25,
					items : [{
								layout : 'form',
								labelWidth : 56,
								labelAlign : 'right',
								items : [{
											xtype : 'textfield',fieldLabel : '邮编',
											name : 'postcode',readOnly : true,
											style : {background : '#dddddd'},
											anchor : '99%',maxLength:6,
											maxLengthText : "邮编最大长度不超过6个字符"
										}]
							}]
				}]
			}, {
				layout : 'column',
				items : [{
					columnWidth : 0.5,
					items : [{
						layout : 'form',
						labelWidth : 56,
						labelAlign : 'right',
						items : [{
							xtype : 'textfield',fieldLabel : 'MSN号',
							name : 'msn',readOnly : true,
							style : {background : '#dddddd'},anchor : '99%',
							vtype : 'email',vtypeText : '请填写正确的MSN格式(如:huarun@hotmail.com)'
						}]
					}]
				}, {
					columnWidth : 0.5,
					items : [{
								layout : 'form',
								labelWidth : 56,
								labelAlign : 'right',
								items : [{
											xtype : 'textfield',fieldLabel : '网址',
											name : 'web',readOnly : true,
											style : {background : '#dddddd'},
											anchor : '99%',maxLength : 30,
											maxLengthText : "网址长度不大于30位"
										}]
							}]
				}]
			}, {
				layout : 'column',
				items : [{
					columnWidth : 0.25,
					items : [{
								layout : 'form',
								labelWidth : 70,
								items : [{
											xtype : 'textfield',fieldLabel : '开户行',
											name : 'bankName',readOnly : true,
											style : {background : '#dddddd'},
											anchor : '99%',maxLength : 30,
											maxLengthText : "开户行长度不大于30位"
										}]
							}, {
								layout : 'form',
								labelWidth : 70,
								items : [{
											xtype : 'textfield',fieldLabel : '联系电话',
											name : 'tel',maxLength : 15,
											maxLengthText : "税号长度不大于15位",readOnly : true,
											style : {background : '#dddddd'},anchor : '99%',
											autoCreate : {tag : 'input',type : 'text',autocomplete : 'off',style : 'ime-mode:disabled'}
										}]
							}]
				}, {
					columnWidth : 0.25,
					items : [{
								layout : 'form',
								labelWidth : 70,
								labelAlign : 'right',
								items : [{
											xtype : 'textfield',fieldLabel : '银行账号',
											name : 'bankCode',readOnly : true,
											style : {background : '#dddddd'},
											anchor : '99%',maxLength : 30,
											maxLengthText : "银行账号长度不大于30位"
										}]
							}, {
								layout : 'form',
								labelWidth : 70,
								labelAlign : 'right',
								items : [{
											xtype : 'textfield',
											fieldLabel : '传真电话',
											name : 'fax',
											maxLengthText : "税号长度不大于15位",
											readOnly : true,
											style : {background : '#dddddd'},
											anchor : '99%',
											autoCreate : {tag : 'input',type : 'text',autocomplete : 'off',style : 'ime-mode:disabled'}
										}]
							}]
				}, {
					columnWidth : 0.5,
					items : [{
								layout : 'form',
								labelWidth : 56,
								labelAlign : 'right',
								items : [{
											xtype : 'textfield',fieldLabel : '发票地址',
											name : 'invoicAddress',readOnly : true,
											style : {background : '#dddddd'},anchor : '99%',
											maxLength : 30,maxLengthText : "发票地址长度不大于30位"
										}]
							}, {
								layout : 'column',
								items : [{
									columnWidth : .5,
									items : [{
										layout : 'form',labelWidth : 56,labelAlign : 'right',
										items : [{
											xtype : 'numberfield',
											fieldLabel : 'QQ号',readOnly : true,
											style : {background : '#dddddd'},
											name : 'qq',regex : /^[1-9]{1}\d{4,12}$/,
											regexText : '请填写正确的qq格式和长度',anchor : '99%'
										}]
									}]
								}, {
									columnWidth : .5,
									items : [{
										layout : 'form',labelWidth : 70,labelAlign : 'right',
										items : [{
											xtype : 'textfield',fieldLabel : 'E-Mail',
											name : 'email',readOnly : true,
											style : {background : '#dddddd'},anchor : '99%',
											vtype : 'email',vtypeText : '请填写正确的邮箱格式(如:huarun@gmail.com)'
										}]
									}]
								}]
							}]
				}]
			}]
		}]
	});

	// 初始化目录
	var tab = new Ext.TabPanel({
		width : 225,region : 'center',activeTab : 0,scope:this,
		items : [{
					title : '目录',layout : 'accordion',
					items : [{
								collapsible : true,
								title : '往来关系',
								xtype : 'treepanel',
								width : 225,
								lines : false,
								height : document.body.clientHeight* 1.0,
								autoScroll : true,
								split : true,
								loader : new Ext.tree.TreeLoader(),
								root : new Ext.tree.AsyncTreeNode({
											expanded : true,
											children : [
												{text : '全部',value : '',leaf : true}, 
												{text : '我的买家',value : '0',leaf : true},
												{text : '我的卖家',value : '1',leaf : true},
												{text : '我的买家和卖家',value : '2',leaf : true}]
										}),
								scope:this,	rootVisible : false,
								listeners : {
									click : function(child) {
										var v = {relation : child.attributes.value,name : '',pyCode : '',contactor : '',isDelete : '0'};
										var jsonAll = Ext.encode(v);
										this.partner_ds.baseParams = {start : 0,limit : 20,jsonAll : jsonAll}
										this.partner_ds.reload();
									},
									scope:this
								}
							}, {
								collapsible : true, title : '删除记录',
								xtype : 'treepanel', width : 225,
								lines : false, height : document.body.clientHeight* 1.0,
								autoScroll : true, split : true,
								loader : new Ext.tree.TreeLoader(),
								root : new Ext.tree.AsyncTreeNode({
											expanded : true,
											children : [
												{text : '全部',value : '2',leaf : true},
												{text : '未删除',value : '0',leaf : true},
												{text : '已删除',value : '1',leaf : true}]
										}),
								rootVisible : false,scope:this,
								listeners : {
									click : function(child) {
					    				var v = {relation : '',name : '',pyCode : '',contactor : '',isDelete : child.attributes.value};
										var jsonAll = Ext.encode(v);
										this.partner_ds.baseParams = {start : 0,limit : 20,jsonAll : jsonAll}
										this.partner_ds.reload();
									},
									scope:this
								}
							}]
				}, {
					collapsible : true,
					height : document.body.clientHeight * 1.0,
					width : 225,lines : false,
					split : true,autoScroll : true,
					title : '查找',items : [query_partner_form]
				}]
	});

	this.navigation = new Ext.Panel({
				title : '导航与搜索',region : 'west',
				split : true,width : 225,
				minSize : 225,maxSize : 225,
				collapsible : true,lines : false,layout : 'fit',
				margins : '3 0 3 3',cmargins : '3 3 3 3',
				items : [tab]
			});
	// 初始化partner表格对象
	var partner_colModel = new Ext.grid.ColumnModel([
			new Ext.grid.RowNumberer(),
              {
				header : "操作",
				xtype:'anchorcolumn',
				width : 250,
				dataIndex : 'act',
				items:[{
					text:"查看",scope:this,permissionId:23,
					handler:this.browsePartner
				},{
					text:"编辑",scope:this,permissionId:24,
					handler:this.editPartner,
					getVisiblity:function(v, meta,record,rowIndex,colIndex,store){			            	       
					      var isDelete = record.get("isDelete");	       
					      if(isDelete==1){return false;}				   
						  return true;
					}
				},{
					text:"删除",
					scope:this,
					permissionId:24,
					handler:this.deletePartner,
					getVisiblity:function(v, meta,record,rowIndex,colIndex,store){			            	       
					      var isDelete = record.get("isDelete");	   
					      if(isDelete==1){return false;}
					      return true;
					}
				},{
					text:"恢复",scope:this,permissionId:24,
					handler:this.revertPartner,
					getVisiblity:function(v, meta,record,rowIndex,colIndex,store){			            	       
					      var isDelete = record.get("isDelete");	       
					      if(isDelete==1){return true;}				   
						  return false;
					}
				},{
					renderer:function(v, meta,record,rowIndex,colIndex,store){
						var str;
						if (record.get("companyId")) {
							
							        str = "<span style='font-size:12px;margin-left:12px;color:green'>"
										  + "<img  style='height:10px;width:10px' src="
										  + Uec3.App.Constants.deskUrl
										  + "/resources/images/default/uec3/save.gif></img>已认证公司</span>";
								} else {
							
									str = "<span style='font-size:12px;margin-left:12px;color:#cc0000'>"
										  + "<img  style='height:10px;width:10px' src="
										  + Uec3.App.Constants.deskUrl
										  + "/resources/images/default/uec3/close.gif></img>未认证公司</span>";
								}							
								return str;
					}			
				}]	
				}, 
				{id : 'name',header : "客户名称",width : 200,sortable : true,dataIndex : 'name'},
				{id : 'taxCode',header : "税号",sortable : true,width : 150,dataIndex : 'taxCode'},
			{header : "负责人",width : 120,dataIndex : 'contactor'},
			{header : "联系电话",width : 150,dataIndex : 'tel'},
			{header : "市",width : 100,dataIndex : 'city'}, {header : "应付款",width : 100,
			dataIndex : 'unpaid',align : 'right'
			},
			{   header : "已付款",width : 100,
				dataIndex : 'paid',align : 'right'}, {
				header : "应收款",width : 100,
				dataIndex : 'unreceived',align : 'right'
			}, {
				header : "已收款",width : 100,
				// renderer : Ext.util.Format.usMoney,
				dataIndex : 'received',align : 'right'
			}, {
				header : "经营项目",id : "business",width : 120,dataIndex : 'business'
			}]);
	// create the Grid
	this.partner_grid = new Ext.grid.GridPanel(
	{
		region : 'center',
		iconCls : 'icon-grid',
		enableColumnMove : false,
		enableColumnMoveResize : false,
		margins : '3 3 3 0',
		activeTab : 0,
		defaults : {autoScroll : true},
		stripeRows : true,
		autoExpandColumn : 'business',
		loadMask : {msg : "...加载数据中"},
		store : this.partner_ds,
		cm : partner_colModel,
		sm : new Ext.grid.RowSelectionModel({moveEditorOnEnter : true,singleSelect : true}),
		viewConfig : {columnsText : '显示的列',scrollOffset : 20,sortAscText : '升序',sortDescText : '降序'},
		tbar : new Ext.app.ModuleToolbar(['-', {
			text : '增加',tooltip : {title : '增加往来单位',text : '您可以点击此处,增加客户或者供应商'},permission : 24,scope:this,
			icon : Uec3.App.Constants.deskUrl+ "/resources/images/default/dd/drop-add.gif",
			handler : function() {
				if (!(this.partner_form.getForm().getEl())) {this.partner_form.getForm().reset();} 
				else {this.partner_form.getForm().getEl().dom.reset();}
				this.partner_form.getForm().findField('id').setValue('');
				this.partner_form.getForm().findField('companyId').setValue('');
				this.partner_form.getForm().findField('areaId').setValue('');
				this.partner_form.getForm().findField('ownerId').setValue('');
				this.partnerAddress_ds.removeAll();
				this.partner_win.buttons[0].hide();
				this.partner_win.buttons[1].hide();
				this.partner_win.buttons[2].hide();
				this.partner_win.buttons[3].hide();
				this.partner_win.buttons[4].show();
				this.partner_win.buttons[5].setText('增加');
				this.partner_win.buttons[5].show();
				this.partner_win.buttons[6].show();
				this.partner_win.setTitle('增加客户-按Esc退出');
				this.partner_win.show();
			}
		}, '-', {
			iconCls : 'icon-search',
			text : '搜索认证公司',
			scope:this,
			tooltip : {title : '搜索认证公司',text : '您可以点击此处,根据身份证或者税号查找已认证公司,只有认证和付过费的用户才拥有此项功能'},
			handler : function() {
				var desktop = Uec3.App.getDesktop();
				Ext.Ajax.request({
					url : Uec3.App.Constants.homeUrl+ '/partner/query_partner!searchPermission.do',
					success : function(res) {
						var result = Ext.decode(res.responseText);
						if (result.success == "OK") {
							this.desktop.launchWindowByParam("checkCertify",{partner_ds : this.partner_ds});
						} else {
							if (result.failure == "notCertify") {
								Ext.Msg.alert("提示","您还没进行认证,或者还未通过认证,请您到公司信息页面完成认证后再进行搜索");
							}
							if (result.failure == "notPaid") {
								Ext.Msg.alert("提示"," 您还未付费,请先去在线管理模块付费并购买你需要的套餐");
							}
						}
					},
					failure : function(res) {Ext.Msg.alert('失败', "网络出现异常，请重先连接");},
					scope:this
				});
			}
		}]),
		bbar : new Ext.PagingToolbar({
					pageSize : 20,
					store : this.partner_ds,
					displayInfo : true,
					display : true,
					displayMsg : '第 {0} - {1} 条  共 {2} 条',
					emptyMsg : "没有记录",
					items : []
				})
	});
	// 列模型对象
	var partnerAddress_colModel = new Ext.grid.ColumnModel([
			new Ext.grid.RowNumberer(),
              {header : "操作",xtype:'anchorcolumn',width : 80,dataIndex : 'act',
				items:[{
					text:"删除",scope:this,permissionId:24,handler:this.deletePartnerAddress
				}]		
				}, {
				header : "省份",width : 80,sortable : true,dataIndex : 'province',
				editor : this.partnerAddress_comboProvince
			}, {
				header : "城市",width : 80,sortable : true,dataIndex : 'city',
				editor : this.partnerAddress_comboCity
			}, {
				header : "区域",width : 80,sortable : true,dataIndex : 'district',
				editor : this.partnerAddress_comboCounty
			},{
				header : "详细地址",width : 80,sortable : true,dataIndex : 'street',
				editor : new Ext.grid.GridEditor(new Ext.form.TextField({}))
			}, {
				header : "邮编",width : 80,sortable : true,
				dataIndex : 'postCode',editor : new Ext.grid.GridEditor(new Ext.form.TextField({}))
			}, {
				header : "收货人姓名",width : 100,
				sortable : true,dataIndex : 'receiverName',editor : new Ext.grid.GridEditor(new Ext.form.TextField({}))
			}, {
				header : "电话",width : 80,sortable : true,
				dataIndex : 'phone',editor : new Ext.grid.GridEditor(new Ext.form.TextField({}))
			}, {
				header : "手机",width : 60,sortable : true,
				dataIndex : 'mobile',editor : new Ext.grid.GridEditor(new Ext.form.TextField({}))
			}
	]);

	// 初始化 partnerAddress表格对象
	this.partnerAddress_grid = new Ext.grid.EditorGridPanel({
				store : this.partnerAddress_ds,
				cm : partnerAddress_colModel,
				viewConfig : {forceFit : true,columnsText : '显示的列',scrollOffset : 30,sortAscText : '升序',sortDescText : '降序'},
				selModel : new Ext.grid.RowSelectionModel({moveEditorOnEnter : true,singleSelect : true}),
				iconCls : 'icon-grid',loadMask : {msg : '数据加载中...'},
				stripeRows : true,autoScroll : true,clicksToEdit : 1,
				tbar : new Ext.Toolbar(['-', {
					text : '增加客户收货地址',scope:this,
					icon : Uec3.App.Constants.deskUrl+ "/resources/images/default/dd/drop-add.gif",
					handler : function() {
						var partnerAddress_record=this.partnerAddress_record;
						var p = new partnerAddress_record({province : '',city : '',district : '',street : '',postCode : '',receiverName : '',phone : '',mobile : ''});
						this.partnerAddress_grid.stopEditing();
						// partnerAddress_ds.insert(0,p); 
						this.partnerAddress_ds.addSorted(p);
						this.partnerAddress_grid.getView().refresh();
						this.partnerAddress_grid.startEditing(0, 0);
					}
				}, '-'])
			});
	var partnerAddressPanel = new Ext.Panel({height : 135,layout : 'fit',items : [this.partnerAddress_grid]});
	this.partner_form = new Ext.form.FormPanel({
		border : false,frame : true,
		title : '往来单位信息',closable : false,height : 250,
		items : [{
			xtype : 'fieldset',
			title : '基本信息',
			height : 145,
			collapsed : false,
			items : [{
				layout : 'column',
				items : [{
					columnWidth : 0.5,
					items : [{
								layout : 'form',
								labelWidth : 70,
								items : [
									{name : 'id',fieldLabel : '客户ID',xtype : 'hidden'}, 
									{name : 'companyId',fieldLabel : '公司ID',xtype : 'hidden'}, 
									{name : 'ownerId',fieldLabel : '拥有者ID',xtype : 'hidden'},
									{name : 'areaId',fieldLabel : '地区ID',xtype : 'hidden'},
									{xtype : 'textfield',fieldLabel : '公司名称(*)',
									name : 'name',anchor : '99%',												
									allowBlank : false,blankText : "往来单位名称不允许为空",
									maxLength:"30",maxLengthText:"最大长度为30位"}]
							}, {
								layout : 'column',
								items : [{
									columnWidth : 0.5,
									items : [{
										layout : 'form',labelWidth : 70,
										items : [{xtype : 'textfield',fieldLabel : '负责人/法人',name : 'contactor',anchor : '99%',maxLength:"30",maxLengthText:"最大长度为30位"}]
									}]
								}, {
									columnWidth : 0.5,
									items : [{
										layout : 'form',labelAlign : 'right',
										labelWidth : 70,
										items : [{
											xtype : 'textfield',fieldLabel : '法人身份证',name : 'contactorIdentityCode',anchor : '99%',
											vtype:"alphanum",alphanumText:"只能输入数字或者字符",maxLength:"30",maxLengthText:"最大长度为30位"
										}]
									}]
								}]
							}, {
								layout : 'column',
								items : [{
									columnWidth : 0.5,
									items : [{
										layout : 'form',labelWidth : 70,
										items : [{layout : 'form',labelWidth : 70,items : [this.partner_comboRelation]}]
									}]
								}, {
									columnWidth : 0.5,
									items : [{
										layout : 'form',labelAlign : 'right',labelWidth : 70,
										items : [{xtype : 'textfield',fieldLabel : '折扣',name : 'discount',anchor : '99%',
										maxLength:"30",maxLengthText:"最大长度为30位",regex : /^[0-9]+$/,regexText : '请输入阿拉伯数字格式'}]
									}]
								}]
							}, {
								layout : 'column',
								items : [{
									columnWidth : 0.5,
									items : [{
										layout : 'form',labelWidth : 70,
										items : [{
											layout : 'form',labelWidth : 70,
											items : [{
												xtype : 'numberfield',name : 'unpaid',fieldLabel : '应付款',readOnly : true,style : {background : '#dddddd'},anchor : '99%'
											}]
										}]
									}]
								}, {
									columnWidth : 0.5,
									items : [{
										layout : 'form',labelAlign : 'right',labelWidth : 70,
										items : [{xtype : 'numberfield',name : 'paid',fieldLabel : '已付款',readOnly : true,style : {background : '#dddddd'},anchor : '99%'}]
									}]
								}]
							}]
				}, {
					columnWidth : 0.5,
					items : [{
								layout : 'form',labelWidth : 56,labelAlign : 'right',
								items : [{xtype : 'textfield',fieldLabel : '经营项目',name : 'business',anchor : '99%',maxLength:"30",maxLengthText:"最大长度为30位"}]
							}, {
								layout : 'column',
								items : [{
									columnWidth : 0.5,
									items : [{
										layout : 'form',labelAlign : 'right',labelWidth : 56,
										items : [{
													xtype : 'textfield',fieldLabel : '税号',name : 'taxCode',anchor : '99%',
													maxLength:"30",maxLengthText:"最大长度为30位",regex : /^[0-9]+$/,regexText : '请输入阿拉伯数字格式',allowNegative:false
												}]
									}]
								}, {
									columnWidth : 0.5,
									items : [{
										layout : 'form',labelWidth : 70,labelAlign : 'right',
										items : [{
													xtype : 'textfield',fieldLabel : '工商注册码',name : 'code',anchor : '99%',allowNegative:false,maxLength:"30",
													regex : /^[0-9]+$/, regexText : '请输入阿拉伯数字格式',maxLengthText:"最大长度为30位"
												}]
									}]
								}]
							}, {
								style : "margin-left:20px;height:26px;color:#cc6699",columnWidth : 0.5, 
								items : []
							}, {
								layout : 'column',
								items : [{
									columnWidth : 0.5,
									items : [{
										layout : 'form',labelAlign : 'right',labelWidth : 56,
										items : [{xtype : 'numberfield',name : 'unreceived',fieldLabel : '应收款',readOnly : true,style : {background : '#dddddd'},anchor : '99%',allowNegative:false}]
									}]
								}, {
									columnWidth : 0.5,
									items : [{
										layout : 'form',
										labelWidth : 70,
										labelAlign : 'right',
										items : [{xtype : 'numberfield',name : 'received',fieldLabel : '已收款',readOnly : true,style : {background : '#dddddd'},anchor : '99%'}]
									}]
								}]
							}]
				}]
			}]
		}, {
			xtype : 'fieldset',title : '联系方式',height : 115,
			items : [{
				layout : 'column',
				items : [
					      {columnWidth : 0.2,
					        items : [{layout : 'form',labelWidth : 70,items : [this.partner_prov_cmb]}]
						}, 
						  {
							columnWidth : 0.15,
							items : [{layout : 'form',labelWidth : 30,items : [this.partner_city_cmb]}]
						},
						  {columnWidth : 0.15,
							items : [{layout : 'form',labelWidth : 30,items : [this.partner_dist_cmb]}]
						}, 
						  {
							columnWidth : 0.25,
							items : [
						            {layout : 'form',labelWidth : 56,labelAlign : 'right',
									items : [{xtype : 'textfield',fieldLabel : '通讯地址',name : 'address',anchor : '99%',maxLength:"30",maxLengthText:"最大长度为30位"}]
									}]
						},
						  {
							columnWidth : 0.25,
							items : [
								    {layout : 'form',labelWidth : 70,labelAlign : 'right',
									items : [{xtype : 'textfield',fieldLabel : '邮编',name : 'postcode',anchor : '99%',allowNegative:false,maxLength:"6",maxLengthText:"邮编最大长度不超过6个字符"}]
									}]
						}]
			}, {
				layout : 'column',
				items : [{
							columnWidth : 0.25,
							items : [
								    {layout : 'form',labelWidth : 70,
										items : [{xtype : 'textfield',fieldLabel : '开户行',name : 'bankName',anchor : '99%',maxLength:"30",maxLengthText:"最大长度为30位"}]
								},
									{
										layout : 'form',labelWidth : 70,
										items : [{xtype : 'textfield',fieldLabel : '联系电话',name : 'tel',anchor : '99%',maxLength:"30",maxLengthText:"最大长度为30位"}]
									}]
					   },{
							columnWidth : 0.25,
							items : [{
										layout : 'form',labelWidth : 70,labelAlign : 'right',
										items : [{
													xtype : 'textfield',fieldLabel : '银行账号',name : 'bankCode',anchor : '99%',allowNegative:false,
													regex : /^[0-9]+$/,regexText : '请输入阿拉伯数字格式',maxLength:"30",maxLengthText:"最大长度为30位"
											}]
									    },
									{
										layout : 'form',labelWidth : 70,labelAlign : 'right',
										items : [{xtype : 'textfield',fieldLabel : '传真电话',name : 'fax',anchor : '99%',maxLength:"30",maxLengthText:"最大长度为30位"}]
									}]
					  },{
							columnWidth : 0.5,
							items : [
								{
									    layout : 'form',labelWidth : 56,labelAlign : 'right',
										items : [{xtype : 'textfield',fieldLabel : '发票地址',name : 'invoicAddress',anchor : '99%',maxLength:"30",maxLengthText:"最大长度为30位"}]
					  },{
									   layout : 'column',
										items : [
								   {
											columnWidth : .5,
											items : [{
												layout : 'form',labelWidth : 56,labelAlign : 'right',
												items : [{xtype : 'textfield',fieldLabel : 'QQ',name : 'qq',anchor : '99%',allowNegative:false,regex : /^[0-9]+$/,regexText : '请输入阿拉伯数字格式',
												maxLength:"30",maxLengthText:"最大长度为30位"}
												]
											}]
										},
									{
											columnWidth : .5,
											items : [{
												layout : 'form',labelWidth : 70,labelAlign : 'right',
												items : [{xtype : 'textfield',fieldLabel : 'E-Mail',name : 'email',anchor : '99%',maxLength:"30",maxLengthText:"最大长度为30位"}]
											}]
										}
									]
								}]
						}]
			}]
		},partnerAddressPanel]
	});
	// 初始化window对象
	var oneWin=this;
	this.win_tab = new Ext.TabPanel({
				region : 'center',width : 1000,margins : '3 3 3 0',activeTab : 0,
				items : [oneWin.partner_form, oneWin.companyForm],
				initEvents : function(){
					Ext.TabPanel.superclass.initEvents.call(this);
					this.mon(this.strip, 'click', this.onTitleClick,this);
				},
				onTitleClick : function(e, target, o) {
					var t = this.findTargets(e);
					var companyId = oneWin.partner_form.getForm().findField("companyId").getValue();
					if (t.item.title == "已认证往来单位注册信息") {
					if (!companyId || companyId == 0) {Ext.MessageBox.alert("提示", "该往来单位还没通过认证"); return;} 
					else {
							oneWin.partner_win.buttons[5].hide();
							oneWin.companyForm.getForm().load({
							url : Uec3.App.Constants.homeUrl+ '/company/query_company!query.do',
							params : {companyId : companyId},
							waitMsg : '加载数据中...',
							success : function(form, action) {},
							failure : function(form, action) {
							Ext.MessageBox.alert("提示", "加载数据失败");}
							});
							t.item.show();
						}
					} else {oneWin.partner_win.buttons[5].show(); t.item.show();}
				}
			});

	this.partner_win=this.desktop.createWindowNoTask({
		layout : 'fit',constraitHeader : true,region : 'center',
		closeAction : 'hide',closable : true,
		width : 1000,height : 520,
		title : '增加客户-按Esc退出',collapsible : true,
		constrait : true,modal : true,
		draggable : true,plain : true,
		header : true,resizable : false,
		maximizable : false,minimizable : false,
		items : [this.win_tab],
		buttons : [{
					style : "margin-right:25px",width : 200,iconCls : "icon-save",text : '已认证公司',disabled : true,disabledClass : "",hidden : true}, 
				    {style : "margin-right:25px;",width : 200,iconCls : "icon-close",text : '未认证公司',disabled : true,disabledClass : "",hidden : true}, 
					{text : '请求查看客户详细信息',hidden : true,scope:this,
					handler : function() {		
						var companyId = this.partner_form.getForm().findField("companyId").getValue();
						if (companyId == 0 || companyId == "") {
							Ext.Msg.alert("提示","请先点击检查认证按钮,确认对方已是认证公司,才能进行这步操作");
							return;
						}
						this.partner_ajax.request({
							url : Uec3.App.Constants.homeUrl+ '/partner/query_partner!sendNotice.do',
							success : function(res) {
								var result = Ext.decode(res.responseText);
								if (result.success == "OK") {Ext.Msg.alert("提示", "发送消息成功");} 
								else {Ext.Msg.alert("提示", result.failure);}
							},
							failure : function(res) {Ext.Msg.alert('失败', "网络出现异常,请重先连接");},
							params : {receiverId : companyId}
						});
					}
				}, {
					iconCls : "",text : '查看客户信息',hidden : true,scope:this,
					handler : function() {
			            var companyId = this.partner_form.getForm().findField("companyId").getValue();
						var id = this.partner_form.getForm().findField("id").getValue();
						var desktop = Uec3.App.getDesktop();
						Ext.Ajax.request({
							url : Uec3.App.Constants.homeUrl+ '/company/query_company!showCompanyMessage.do',
							success : function(res) {
							var result = Ext.decode(res.responseText);
								if (result.success == "OK") {
									if (result.message == 1) {this.desktop.launchWindowByParam("simpleCompanyMessage",{partnerId : id,id : companyId,isHiddenButton : true});}
									if (result.message == 2) {this.desktop.launchWindowByParam("retailCompanyMessage",{companyId : companyId});}
								} else {Ext.Msg.alert("提示", result.failure);}
							},
					       failure : function(res) {Ext.Msg.alert('失败', "网络出现异常，请重先连接");},
						   params : {companyId : companyId}
						});
					}
				},
				   {
					text : '检查客户是否认证',iconCls:"icon-isCertify",scope:this,
					tooltip : {
						title : '检查客户是否认证',
						text : '您可以点击此处,根据法人身份证或者税号查找已认证公司,只有认证和付过费的用户才拥有此项功能'
					},
					hidden : true,
					handler : function() {
						var id = this.partner_form.getForm().findField("id").getValue();
						if (!id) {
							Ext.Msg.alert("提示","请先点击增加按钮,增加客户后才能进行这步操作")
							return;
						}
						Ext.Ajax.request({
							url : Uec3.App.Constants.homeUrl+ '/partner/query_partner!searchPermission.do',
							success : function(res) {
							var result = Ext.decode(res.responseText);
							if (result.success == "OK") {this.desktop.launchWindowByParam("checkCertify", {id:id,partner_ds:this.partner_ds,partner_form:this.partner_form});} 
							else {
							   if (result.failure == "notCertify") {Ext.Msg.alert("提示","您还没进行认证,或者还未通过认证,请您到公司信息页面完成认证后再进行搜索");}
							   if (result.failure == "notPaid") {Ext.Msg.alert("提示"," 您还未付费,请先去在线管理模块付费并购买你需要的套餐");}
							  }
							},
							failure : function(res) {Ext.Msg.alert('失败', "网络出现异常，请重先连接");},
							scope:this
						});
					}
				}, {
					text : '保存',iconCls : "icon-save", scope:this,
					handler : function(){this.savePartner(this.partner_win, this.partner_form, this.partner_ds,this.partnerAddress_ds);}
				}, {
					text : '关闭',iconCls : "icon-close",scope:this,
					handler : function() {this.partner_win.hide();}
				}],
		buttonAlign : 'center'
	});
		
},
		
init : function(config) {
	this.initComponent(config);
	this.initEvent(config);
	return [this.navigation, this.partner_grid];
},

initComponent : function(config) {
	this.getPartnerCommonObject(config);
	this.getAndRestorePartner(config);
	this.componentInitsPartner(config);
},

initEvent : function(config) {
	
	this.on('show', function() {
					this.partner_ds.load({callback : function(records, options, success) {
					if (success) {} else {Ext.Msg.alert('提示', "网络连接异常...请稍候再试");}}});}, this, {single : true});
	
	this.partnerAddress_comboProvince.on('select',
			function(comboBox, record) {
				var value = record.get("id");
				var selection = this.partnerAddress_grid.getSelectionModel().getSelected();
				if (selection.get("provinceId") != value) {
					selection.set("provinceId", value); selection.set("areaId", value);
					selection.set("city", ""); selection.set("district", "");
				}},this);

	this.partnerAddress_comboCity.on('beforeshow', function(comboBox) {
				var selection = this.partnerAddress_grid.getSelectionModel().getSelected();
				var provinceId = selection.get('provinceId');
				var lastProviceId = comboBox.getStore().baseParams.prov;
				if (lastProviceId != provinceId) {
					this.partnerAddress_comboCity.clearValue(); this.partnerAddress_storeCity.removeAll();
					this.partnerAddress_storeCity.baseParams.prov = provinceId; this.partnerAddress_storeCity.load();
				}},this);

	this.partnerAddress_comboCounty.on('beforeshow', function(comboBox) {
				var selection = this.partnerAddress_grid.getSelectionModel().getSelected();
				var cityId = selection.get('cityId');
				var lastCityId = comboBox.getStore().baseParams.city;
				if (lastCityId != cityId) {
					this.partnerAddress_comboCounty.clearValue();this.partnerAddress_storeCounty.removeAll();
					this.partnerAddress_storeCounty.baseParams.city = cityId;this.partnerAddress_storeCounty.load();
				}},this);

	this.partnerAddress_comboCity.on('select', function(comboBox, record) {
				var value = record.get('id');
				var selection = this.partnerAddress_grid.getSelectionModel().getSelected();
				if (selection.get("cityId") != value) {
					selection.set("areaId", value);selection.set("cityId", value);selection.set("district", "");}},this);

	this.partnerAddress_comboCounty.on('select', function(comboBox, record) {
				var selection = this.partnerAddress_grid.getSelectionModel().getSelected();
				selection.set("areaId", record.get('id'));},this)

	this.partner_ajax.on('beforerequest', function() {Ext.MessageBox.wait("保存数据中...", "提示");},this);

	this.partner_ajax.on('requestcomplete', function() {Ext.MessageBox.hide();},this);

	this.partner_prov_cmb.on('select', function(combo) {var value = combo.getValue();
	this.partner_form.getForm().findField("areaId").setValue(value);},this);

	this.partner_city_cmb.on('select', function(combo) {
				var value = combo.getValue();
				this.partner_form.getForm().findField("areaId").setValue(value);},this);

	this.partner_dist_cmb.on('select', function(combo) {var value = combo.getValue();this.partner_form.getForm().findField("areaId").setValue(value);},this);

	this.partner_win.on("show", function() {
		this.keymap = new Ext.KeyMap(this.partner_win.id, 
		{key : 13,fn : function(){this.savePartner(this.partner_win, this.partner_form, this.partner_ds,this.partnerAddress_ds);},scope : this});
		this.win_tab.setActiveTab(0);
		this.maskTopField = new Ext.LoadMaskJUPIT(this.partner_form.id);
		formBingingKeys(this.partner_form, this.partner_win);}, this);
	
	this.partner_win.on("hide", function() {this.keymap.setDisabled(true);if (this.maskTopField){this.maskTopField.hide()};},this);
				
	this.companyForm.getForm().on('actioncomplete', function(form) {
		var rootFirstValue = form.reader.jsonData.root;
		this.company_prov_cmb.setRawValue(rootFirstValue.province);
		this.company_city_cmb.setRawValue(rootFirstValue.city);
		this.company_dist_cmb.setRawValue(rootFirstValue.district);
		if (rootFirstValue.province != "") {
			this.company_city_cmb.getStore().setBaseParam("prov",rootFirstValue.provinceId);
			this.company_city_cmb.getStore().load();
		}
		if (rootFirstValue.city != "") {
			this.company_dist_cmb.getStore().setBaseParam("city",rootFirstValue.cityId);
			this.company_dist_cmb.getStore().load();
		}},this);
		
    this.partnerAddress_grid.on("afteredit",function(e){
    	if(e.record.get("postCode").length>6){Ext.MessageBox.alert("错误提示","邮编最大长度不超过6个字符",function(){this.partnerAddress_ds.rejectChanges();},this)};
    	if(e.record.get("receiverName").length>30){Ext.MessageBox.alert("错误提示","接收人姓名最大长度不超过30个字符",function(){this.partnerAddress_ds.rejectChanges();},this)};
    	if(e.record.get("phone").length>30){Ext.MessageBox.alert("错误提示","电话号码最大长度不超过30个字符",function(){this.partnerAddress_ds.rejectChanges();},this)}
    	if(e.record.get("mobile").length>30){Ext.MessageBox.alert("错误提示","手机号码最大长度不超过30个字符",function(){this.partnerAddress_ds.rejectChanges();},this)}
    },this)	
	 	
    }	
});

Uec3.PartnerWindow = Ext.extend(Ext.app.Module, {
	id : 'partner',
	type : 'common/partner',
	init : function(initParams) {},
	constructor : function(config) {Uec3.PartnerWindow.superclass.constructor.call(this);},
	initEvent : function(params) {this.win.fireEvent("show");},
	createWindow : function(params) {
	  this.win = new Uec3.PartnerPWindow({module : this,params : params});
	  this.initEvent(params);
      this.win.show();
	}
});